package cn.tedu.jdbc;

import java.sql.*;

public class JDBCUtils2 {
    public static  Connection get() throws Exception {
        Class.forName("com.mysql.jdbc.Driver");
        String url="jdbc:mysql://localhost:3307/cgb211101";
        Connection c = DriverManager.getConnection(url,"root","root");
        return c;
    }

    public static  void close(ResultSet r, PreparedStatement p,Connection c)  {
        if (r!=null){
            try {
                r.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }finally {
                r=null;
            }
        }
        if (p!=null){
            try{
                p.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }finally {
                p=null;
            }
        }
        if (c!=null){
            try {
                c.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }finally {
                c=null;
            }
        }
    }
}

